package org.geometerplus.android.fbreader;

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.widget.Button;

import org.geometerplus.fbreader.fbreader.FBReaderApp;

import java.util.ArrayList;

public abstract class ButtonsPopupPanel extends PopupPanel implements View.OnClickListener {
//	public class ActionButton extends ZoomButton {
//		final String ActionId;
//		final boolean IsCloseButton;
//
//		public ActionButton(Context context, String actionId, boolean isCloseButton) {
//			super(context);
//			ActionId = actionId;
//			IsCloseButton = isCloseButton;
//		}
//	}

	public class ActionButton extends Button {
		final String ActionId;
		final String SelectionStr;
		final boolean IsCloseButton;
		

		public ActionButton(Context context, String actionId, String selectionStr, boolean isCloseButton) {
			super(context);
			ActionId = actionId;
			SelectionStr = selectionStr;
			IsCloseButton = isCloseButton;
		}
	}	
	
	private final ArrayList<ActionButton> myButtons = new ArrayList<ActionButton>();

	public ButtonsPopupPanel(FBReaderApp fbReader) {
		super(fbReader);
	}

//	protected void addButton(String actionId, boolean isCloseButton, int imageId) {
//		final ActionButton button = new ActionButton(myWindow.getContext(), actionId, isCloseButton);
//		button.setImageResource(imageId);
//		myWindow.addView(button);
//		button.setOnClickListener(this);
//		myButtons.add(button);
//	}
	
	protected void addButton(String actionId, String selectonStr, boolean isCloseButton, int imageId) {
		final ActionButton button = new ActionButton(myWindow.getContext(), actionId, selectonStr, isCloseButton);
		button.setText(selectonStr);
		button.setTextColor(Color.WHITE);
		button.setBackgroundResource(imageId);
		myWindow.addView(button);
		button.setOnClickListener(this);
		myButtons.add(button);
	}

	@Override
	protected void update() {
		for (ActionButton button : myButtons) {
			button.setEnabled(Application.isActionEnabled(button.ActionId));
		}
	}

	public void onClick(View view) {
		final ActionButton button = (ActionButton)view;
		Application.runAction(button.ActionId);
		if (button.IsCloseButton) {
			storePosition();
			StartPosition = null;
			Application.hideActivePopup();
		}
	}
}
